using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using LD24.Entities;
using LD24.Helpers;

namespace LD24
{
    public class LDGame : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public static ContentManager CONTENT;
        public static Random RANDOM;

        World world;
        Camera camera;

        public LDGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            CONTENT = Content;
            RANDOM = new Random();

            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;
        }

        protected override void Initialize()
        {

            world = new World();
            camera = new Camera();
            base.Initialize();
        }

        protected override void LoadContent()
        {
            ImageHelper.getImage("block");
            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        protected override void UnloadContent()
        {
          
        }

        protected override void Update(GameTime gameTime)
        {
            KeyboardHelper.Update();
            camera.Update();
            world.Update(gameTime);
            base.Update(gameTime);
        }

        public static int DRAW_COUNT = 0;
        protected override void Draw(GameTime gameTime)
        {
            DRAW_COUNT = 0;
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin( SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, camera.getTransformation(GraphicsDevice) );

            world.Draw(spriteBatch,gameTime);
           
            spriteBatch.End();
            Console.WriteLine(DRAW_COUNT.ToString());
            base.Draw(gameTime);
        }
    }
}
